package com.example.zhaoping.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhaoping.entity.PageParam;
import com.example.zhaoping.entity.Position;
import com.example.zhaoping.entity.Recruitment;
import com.example.zhaoping.mapper.PositionMapper;
import com.example.zhaoping.service.PositionSerice;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PositionSericeImpl implements PositionSerice {

    @Resource
    private PositionMapper positionMapper;

    @Override
    public Page<Position> selectList(PageParam param) {
        Page<Position> page = new Page<>(param.getPageNum(),param.getPageSize());
        page.addOrder(OrderItem.asc("releaseTime"));
        QueryWrapper<Position> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("valid",1);
        if(!param.getKeyword().equals("")){
            queryWrapper.and(positionQueryWrapper ->
                    positionQueryWrapper.like("job",param.getKeyword())
                    .or().like("description",param.getKeyword())
                    .or().like("name",param.getKeyword()).or().like("name",param.getKeyword())
            );
        }
        Page jobList = positionMapper.selectPage(page,queryWrapper);
        return jobList;
    }

    @Override
    public Position getPosition(Integer id) {
        Position position = positionMapper.selectById(id);
        int views = position.getViews();
        position.setViews(views+1);
        System.out.println(position);
        positionMapper.updateById(position);
        return positionMapper.selectById(id);
    }

}
